package cn.itsource.ymcc.service.impl;

import cn.itsource.ymcc.constants.BaseConstants;
import cn.itsource.ymcc.domain.KillActivity;
import cn.itsource.ymcc.dto.KillActivitySaveParamDto;
import cn.itsource.ymcc.mapper.KillActivityMapper;
import cn.itsource.ymcc.service.IKillActivityService;
import cn.itsource.ymcc.service.IKillCourseService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author whale
 * @since 2021-12-02
 */
@Service
@Slf4j
public class KillActivityServiceImpl extends ServiceImpl<KillActivityMapper, KillActivity> implements IKillActivityService {

    @Autowired
    private IKillCourseService killCourseService;

    @Override
    public void save(KillActivitySaveParamDto dto) {
        KillActivity killActivity = new KillActivity();
        killActivity.setName(dto.getName());
        killActivity.setBeginTime(dto.getBeginTime().getTime());
        killActivity.setEndTime(dto.getEndTime().getTime());
        killActivity.setPublishStatus(BaseConstants.KillActivity.STATUS_PUBLISH_WAIT);
        String timeStr = BaseConstants.DATE_FORMAT_MM_DD_HOURSE_MINI.format(dto.getBeginTime());
        killActivity.setTimeStr(timeStr);
        log.info("添加秒杀活动 -> {}",killActivity);
        insert(killActivity);
    }
}
